<template>
  <div class="fill-width-height">
    <el-card>
      <template #header>
        <h2>广告位配置</h2>
      </template>
      <el-form ref="formRef" :model="formData" label-width="150px">
        <el-form-item label="广告位id">
          <el-input v-model="formData.adUnitId" placeholder="广告位id"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="saveConfig">保存配置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { getAdUnitIdConfig, saveAdUnitIdConfig } from '@/api/imgManage/appManage'

export default {
  name: 'MiniProgramConfig',
  components: {},
  props: {},
  data() {
    return {
      formData: {
        adUnitId: '',
      }
    };
  },
  computed: {},
  methods: {
    fetchConfigList() {
      getAdUnitIdConfig().then(response => {
        this.formData = response.data;
      }).catch(error => {
        console.error('获取配置列表失败:', error);
      });
    },
    saveConfig() {
      saveAdUnitIdConfig( {
        adUnitId: this.formData.adUnitId
      }).then(response => {
        this.$message.success('配置保存成功');
      })
        .catch(error => {
          this.$message.success('配置保存失败，'+ error);
        });
    }
  },
  mounted() {
    this.fetchConfigList()
  }
};
</script>

<style scoped lang="scss">
</style>
